/*
 Author:du
 Time:2017.11.3
*/

namespace FutureCoreEditor
{
    public static class StringExtend
    {
        private const string BoolTrueStr = "1";

        public static int ToInt(this string str)
        {
            int temp = 0;
            int.TryParse(str, out temp);
            return temp;
        }

        public static uint ToUint(this string str)
        {
            uint temp = 0;
            uint.TryParse(str, out temp);
            return temp;
        }

        public static long ToLong(this string str)
        {
            long temp = 0;
            long.TryParse(str, out temp);
            return temp;
        }

        public static ulong ToUlong(this string str)
        {
            ulong temp = 0;
            ulong.TryParse(str, out temp);
            return temp;
        }

        public static float ToFloat(this string str)
        {
            float temp = 0;
            float.TryParse(str, out temp);
            return temp;
        }

        public static bool ToBool(this string str)
        {
            bool temp = false;
            if (str == BoolTrueStr) temp = true;
            return temp;
        }

        public static int[] ToIntOneArray(this string str)
        {
            if (str.Equals(string.Empty))
            {
                return null;
            }
            return SplitUtil.SemicolonToIntOneArray(str);
        }

        public static int[][] ToIntTwoArray(this string str)
        {
            if (str.Equals(string.Empty))
            {
                return null;
            }
            return SplitUtil.VerticalBarSemicolonToIntTwoArray(str);
        }

        public static string[] ToStringOneArray(this string str)
        {
            if (str.Equals(string.Empty))
            {
                return null;
            }
            return SplitUtil.Semicolon(str);
        }

        public static string[][] ToStringTwoArray(this string str)
        {
            if (str.Equals(string.Empty))
            {
                return null;
            }
            return SplitUtil.VerticalBarSemicolon(str);
        }
    }
}